#include "Array2D.h"

CArray2D::CArray2D(int _im, int _jm)
: imax(_im), jmax(_jm)
{
	if (imax<=0 || jmax<=0)
		throw BadSize();

	arr2D = new int*[imax];
	
	for(int i=0; i<imax; i++)
		arr2D[i] = new int[jmax];
}

CArray2D::~CArray2D(void)
{
	for(int i=0; i<imax; i++)
		delete [] arr2D[i];

	delete [] arr2D;
}


int& CArray2D::operator() (int i, int j)
{
	if (i>=imax || j>=jmax || i<0 || j<0)
	{
		//throw BoundsViolations();		Return empty cell when hero goes out of bounds
		bViol = 32;
		return bViol;
	}
	return arr2D[i][j];
}


const int& CArray2D::operator() (int i, int j) const
{
	if (i>=imax || j>=jmax || i<0 || j<0)
	{
		//throw BoundsViolations();		Return empty cell when hero goes out of bounds
		bViol = 32;
		return bViol;
	}
	return arr2D[i][j];
}